'''
Created on 2010-12-21

@author: Administrator
'''
from util import DB

def getPageAlias(url):
    i = url.find(".action")
    if i == -1:
        return url[:8]
    else:
        s = url.rfind("/")
        return url[s+1:i]

def genBasket():
    f=open('d:/tmp/sample2.basket','w')
    
    cur=DB.getCur()
    count = cur.execute("select sess_key,url from simplesession order by sess_key")
    sk=""
    for i in range(count):
        t=cur.fetchone()
        if t[0] == sk:
            f.write(",%s"%getPageAlias(t[1]))
        else:
            sk = t[0]
            f.write("\n%s"%getPageAlias(t[1]))
    
    f.flush()
    f.close()
    print "convertion done!"

if __name__ == '__main__':
    genBasket()